Skip to content

[clang-repl] Improve error message on failed undos #149396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

aadanen
Copy link

@aadanen aadanen commented Jul 17, 2025

Updated error message logic for undo function. Throws different errors for the case of there being nothing to undo, and for the case of requesting more undos than there are operations to undo.

Fixes #143668

aadanen and others added 3 commits July 16, 2025 19:44
used grep -r "Too many undos" to locate all instances where the string
was mentioned. Changed the string to the suggestion in issue 143668
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 17, 2025

@llvm/pr-subscribers-clang

Author: Aaron Danen (aadanen)

Changes

Hi all. This is my first pull request to an open source project. I am a student so have mercy on me!

I have done my best to read all of the relevant documentation about how to contribute most effectively but its totally possible I've made a mistake or missed something. Please let me know so I can do better next time :)

I found a simple issue and have done my best to resolve it. I believe this change resolves #143668

All i did was grep -r "Too many undos" and replace all instances of that string with the suggested replacement.

thank you for your time
aadanen


Full diff: https://github.com/llvm/llvm-project/pull/149396.diff

2 Files Affected:

  • (modified) clang/lib/Interpreter/Interpreter.cpp (+1-1)
  • (modified) clang/unittests/Interpreter/InterpreterTest.cpp (+2-2)
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index ed3bae59a144c..a2696f78cb510 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -754,7 +754,7 @@ llvm::Error Interpreter::Undo(unsigned N) {
 
   if (N > getEffectivePTUSize())
     return llvm::make_error<llvm::StringError>("Operation failed. "
-                                               "Too many undos",
+                                               "No input left to undo",
                                                std::error_code());
   for (unsigned I = 0; I < N; I++) {
     if (IncrExecutor) {
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index b97f5ae17c9f0..2ec65e2a9b2ef 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -158,12 +158,12 @@ TEST_F(InterpreterTest, UndoCommand) {
 
   // Fail to undo.
   auto Err1 = Interp->Undo();
-  EXPECT_EQ("Operation failed. Too many undos",
+  EXPECT_EQ("Operation failed. No input left to undo",
             llvm::toString(std::move(Err1)));
   auto Err2 = Interp->Parse("int foo = 42;");
   EXPECT_TRUE(!!Err2);
   auto Err3 = Interp->Undo(2);
-  EXPECT_EQ("Operation failed. Too many undos",
+  EXPECT_EQ("Operation failed. No input left to undo",
             llvm::toString(std::move(Err3)));
 
   // Succeed to undo.

@DavidSpickett
Copy link
Collaborator

Hi all. This is my first pull request to an open source project. I am a student so have mercy on me!

Welcome!

All i did was grep -r "Too many undos" and replace all instances of that string with the suggested replacement.

Simple and effective but, there is a little bit more context in this case, which I'll explain in a review comment in a moment.

Some admin stuff:

  • We prefer that PRs (which become git commits) have a title of the form "[some project tags] ". So in this case I did git log -- clang/lib/Interpreter/Interpreter.cpp and concluded that it's probably [clang-repl]. This isn't some machine enforced thing, it just helps us humans recognise the changes later in logs and emails.
  • The PR description will become the git commit's message (this is a setting GitHub allows projects to change, so you may see it work other ways in other projects). Which means that the PR description is more commit message, less cover letter. What I tend to do is put that sort of thing in a new comment.

Having said that, I think you'll be better able to describe the change once we've gone through some review. So leave both of those as is, for now, and we'll make sure they're ok later.

Another thing that you may not have had to do for the change as is, but will when I explain a bit more, is run the tests locally. So if you haven't already, follow https://llvm.org/docs/GettingStarted.html and get to the point where you can build clang. From there you can either use ninja check-clang or ninja check-clang-unit. The latter is just a specific subset of tests, which does cover what you're modifying here.

In addition to that, our CI will be running tests for you but it is much more useful to have them running locally so your edit -> run -> edit loop can be faster.

Copy link

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Developer Policy and LLVM Discourse for more information.

@DavidSpickett
Copy link
Collaborator

DavidSpickett commented Jul 18, 2025

#149396 (comment) is one of our automated checks, please follow its guidance. The reason we do this is so we can attribute changes for reasons around the licensing of contributions, there's more info in those links. It can be any valid address, you don't have to use a "personal" one, for instance I use my email address provided by my employer (that and they require that I do, but beside the point).

@aadanen aadanen changed the title Issue143668 [clang-repl] Jul 19, 2025
@aadanen
Copy link
Author

aadanen commented Jul 19, 2025

  1. I am able to build clang, compile the project, and I am currently running the "ninja check-clang-unit" tests. Although it does take an incredibly long time ( 45 minutes to an hour) but that's off topic

  2. I attached my email

  3. I think I understand what you're describing as far as how the code should be smarter. I will investigate and try to figure out where that edit will take place.

  4. some of the commits in this PR are me updating the branch with changes to the main branch. I think its okay because this whole thing will get squashed at the end but just checking

differentiate between the case of 0 inputs to undo and the case when
there are X inputs and Y requested undos but Y > X
@aadanen
Copy link
Author

aadanen commented Jul 19, 2025

I put in inputs vs undo requests logic but I think the unit test might need to be edited as well

@aadanen
Copy link
Author

aadanen commented Jul 21, 2025

Okay I think that does it :)

@aadanen aadanen changed the title [clang-repl] [clang-repl] Improve error message on failled undos Jul 21, 2025
@DavidSpickett DavidSpickett changed the title [clang-repl] Improve error message on failled undos [clang-repl] Improve error message on failed undos Jul 21, 2025
@DavidSpickett DavidSpickett requested a review from vgvassilev July 21, 2025 08:43
@DavidSpickett
Copy link
Collaborator

Looks great! CI should confirm the test is correct, and I added the clang-repl maintainer on review in case they have anything to say.

Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions cpp -- clang/lib/Interpreter/Interpreter.cpp clang/unittests/Interpreter/InterpreterTest.cpp
View the diff from clang-format here.
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 64c6bcf3f..9b714860c 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -767,8 +767,9 @@ llvm::Error Interpreter::Undo(unsigned N) {
                                                std::error_code());
   } else if (N > getEffectivePTUSize()) {
     return llvm::make_error<llvm::StringError>(
-        llvm::formatv("Operation failed. Wanted to undo {0} inputs, only have {1}.",
-            N, getEffectivePTUSize()),
+        llvm::formatv(
+            "Operation failed. Wanted to undo {0} inputs, only have {1}.", N,
+            getEffectivePTUSize()),
         std::error_code());
   }
 

@DavidSpickett
Copy link
Collaborator

I am able to build clang, compile the project, and I am currently running the "ninja check-clang-unit" tests. Although it does take an incredibly long time ( 45 minutes to an hour) but that's off topic

llvm/clang is not a light build at the best of times, but there are some things you can try - https://llvm.org/docs/GettingStarted.html#common-problems

If you do pick up another issue, I can give you some tailored suggestions for the specific task. For instance here, "check-clang" is runs all clang checks but I happened to know that the test you're changing is what we call a "unit test" and has it's own smaller target.

some of the commits in this PR are me updating the branch with changes to the main branch. I think its okay because this whole thing will get squashed at the end but just checking

That's right. In fact I think those "merge" commits are preferred during review, versus rebasing, because GitHub likes to hide review state if you do the latter. It's also fine to not update the PR branch until review has concluded.

@DavidSpickett
Copy link
Collaborator

You have formatting to fix, I suggest you just copy and paste the diff in this one time.

Folks will have different ways to setup clang-format, I use the script https://clang.llvm.org/docs/ClangFormat.html#script-for-patch-reformatting and manually run it (because I am too lazy to integrate it somewhere :) ).

I also add "black" for python formatting, into one giant command:

git diff -U0 --no-color --relative HEAD^ | ./clang/tools/clang-format/clang-format-diff.py -p1 -i -binary /home/david.spickett/build-llvm-aarch64/bin/clang-format && darker --revision HEAD~1 $(git diff-tree --no-commit-id --name-only HEAD -r)

If you're using an editor, do look into applying the format on save, it's much more convenient.

Copy link
Contributor

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm! Thank you @aadanen!

Copy link
Collaborator

@DavidSpickett DavidSpickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aadanen you won't be able to merge this yourself but I can once you've fixed the formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category clang-repl
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clang-repl %undo message is misleading when there is nothing left to undo
4 participants